/*
 * CreepBlueBox.java
 *
 * Created on December 29, 2007, 12:49 PM
 *
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package hextd.creep;

import hextd.util.Cache;
import hextd.util.Geometry;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;

/**
 *
 * @author hylke
 */
public class CreepBlueBox extends CreepBase {

	public static String type = "bb";
	//
	private int prevPaintTime;
	private Color bodyColor = new Color(50, 50, 255);
	private Stroke bodyStroke;
	private Shape[] bodyShapes;
	private int bodyStep = 0;
	private static String infoText =
			"<h1>Blue Box</h1>"
			+ "<p>"
			+ "It's a box, and it's blue.<br>"
			+ "That means it's vulnerable to blue towers, and resistant agains yellow towers."
			+ "</p>";

	/**
	 * Creates a new instance of CreepBlueBox
	 */
	public CreepBlueBox() {
		super("Blue Box");
		this.damageColor = Creep.COLOR.BLUE;
		this.damageColorAnti = Creep.COLOR.YELLOW;
	}

	@Override
	public String getType() {
		return type;
	}

	@Override
	public String getInfoString() {
		return CreepBlueBox.infoText
				+ "<p>" + super.getInfoString() + "</p>";
	}

	@Override
	public void resetScale() {
		super.resetScale();
		Cache cache = cn.getCache();

		if (cache.hasShapeArr("ESBBShapes" + this.size.letter)) {
			this.bodyShapes = cache.getShapeArr("ESBBShapes" + this.size.letter);
		} else {
			this.bodyShapes = new Shape[16];

			double dr = 2.0 * Math.PI / 16;
			double r = 0;
			for (int i = 0; i < this.bodyShapes.length; i++) {

				float scale = paintScale * this.size.scaleMod;
				float[][] points = {
					{+scale * (5.5f + (float) Math.sin(+r)) / 24, +scale * (5.5f + (float) Math.cos(+r)) / 24},
					{+scale * (5.5f + (float) Math.cos(-r)) / 24, -scale * (5.5f + (float) Math.sin(-r)) / 24},
					{-scale * (5.5f + (float) Math.sin(-r)) / 24, -scale * (5.5f + (float) Math.cos(-r)) / 24},
					{-scale * (5.5f + (float) Math.cos(+r)) / 24, +scale * (5.5f + (float) Math.sin(+r)) / 24}
				};
				this.bodyShapes[i] = Geometry.coordsToGeneralPath(points, true);
				r += dr;
			}
			cache.putShapeArr("ESBBShapes" + this.size.letter, this.bodyShapes);
		}
		this.bodyStroke = new BasicStroke(2.5f * strokeScale, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER);
	}

	@Override
	public void paint(Graphics2D g2, int gameTime) {
		if (inactive || dead) {
			this.prevPaintTime = gameTime;
		} else {
			Stroke defaultStroke = g2.getStroke();
			bodyStep += gameTime - prevPaintTime;
			if (bodyStep >= bodyShapes.length) {
				bodyStep = 0;
			}
			if (bodyStep < 0) {
				bodyStep = 0;
			}
			prevPaintTime = gameTime;

			AffineTransform saveXform = g2.getTransform();
			g2.transform(atTranslate);

			if (shielded) {
				paintShield_bottom(g2);
			}
			paintHealthLine(g2);

			g2.setColor(bodyColor);
			g2.setStroke(bodyStroke);
			g2.draw(bodyShapes[bodyStep]);
			g2.setTransform(saveXform);

			if (shielded) {
				g2.transform(atTranslate);
				paintShield_top(g2);
				g2.setTransform(saveXform);
			}

			super.paintSelected(g2);

			g2.setStroke(defaultStroke);
		}
	}
}
